<template>
  <div id="workCheckTopSearch">
    <h1 class="con-right-title">
      作品内容审核
    </h1>
    <div class="search-box">
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="formInline"
        class="demo-form-inline"
      >
        <el-form-item label="人审结果" prop="checkStatus">
          <el-select v-model="formInline.checkStatus" clearable placeholder="">
            <el-option
              v-for="item in checkStatuList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="机审结果" prop="maintainCheckStatus">
          <el-select
            v-model="formInline.maintainCheckStatus"
            clearable
            placeholder=""
          >
            <el-option
              v-for="item in machineStatuList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="排序规则" prop="sortRule">
          <el-select v-model="formInline.sortRule" placeholder="">
            <el-option
              v-for="(item, index) in orderList"
              :key="'item' + index"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="作品类型" prop="workType">
          <el-select v-model="formInline.workType" clearable placeholder="">
            <el-option
              v-for="item in workTypeList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="内容查询" prop="content">
          <el-input
            clearable
            v-model="formInline.content"
            placeholder="输入文字内容搜索"
          ></el-input>
        </el-form-item>
        <el-form-item label="选择学院" prop="categoryId">
          <el-select v-model="formInline.categoryId" placeholder="" clearable>
            <el-option
              v-for="item in collegeList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="用户搜索" prop="userValue">
          <el-input
            v-model="formInline.userValue"
            placeholder="请输入相应的搜索内容"
          >
            <el-select
              slot="prepend"
              v-model="formInline.userType"
              placeholder="请选择"
            >
              <el-option label="大鹏号" value="DAPENGACCOUNT"></el-option>
            </el-select>
          </el-input>
        </el-form-item>

        <el-form-item prop="timeRule">
          <el-select v-model="formInline.timeRule">
            <el-option
              v-for="(item, index) in timeTypeList"
              :key="'item' + index"
              :label="item.key"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="createTime">
          <el-date-picker
            v-model="formInline.createTime"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="时间线" prop="timeLine">
          <el-select v-model="formInline.timeLine" placeholder="">
            <el-option
              v-for="item in timeLineList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="审核人" prop="checkUserId">
          <el-select
            v-model="formInline.checkUserId"
            clearable
            placeholder=""
            filterable
          >
            <el-option
              v-for="(item, index) in personList"
              :key="'item' + index"
              :label="item.nickname"
              :value="item.dapengUserId"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="展示方式" prop="displayRule">
          <el-select v-model="formInline.displayRule" clearable placeholder="">
            <el-option
              v-for="item in displayRuleList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="关联活动" prop="activityId">
          <el-select
            v-model="formInline.activityId"
            clearable
            placeholder=""
            filterable
          >
            <el-option
              v-for="(item, index) in linkActiveList"
              :key="'item' + index"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="用户属性" prop="userAttribute">
          <el-select v-model="formInline.userAttribute" clearable>
            <el-option
              v-for="item in userAttList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button
            type="success"
            icon="el-icon-search"
            @click="toSearch('ruleForm')"
          >
            查询
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import {
  sysNormalDisable,
  getWorkListActivities
} from '@utils/dictionariesFunc'
import { getDpNum } from '@/api/system/user'

export default {
  name: 'workCheckTopSearch',
  msg: '作品内容审核-顶部搜索',
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          categoryId: '', // 选择学院
          checkStatus: '', // 人审结果
          maintainCheckStatus: '', // 机审结果
          content: '', // 内容查询
          sortRule: '', // 排序规则
          workType: '', // 作品类型
          timeRule: '', // 时间
          timeLine: '', // 时间线
          checkUserId: '', // 审核人
          displayRule: '', // 展示方式
          dpAccount: '',
          userType: '',
          activityId: '',
          userAttribute: '', // 用户属性
          createTime: []
        }
      }
    }
  },
  data() {
    return {
      // 人审结果
      checkStatuList: [{ dictLabel: '全部', dictValue: '' }],
      // 机审结果
      machineStatuList: [{ dictLabel: '全部', dictValue: '' }],
      orderList: [],
      // 审核人
      personList: [{ nickname: '全部', dapengUserId: '' }],
      // 作品类型
      workTypeList: [{ dictLabel: '全部', dictValue: '' }],
      timeTypeList: [
        { key: '作品发布时间', value: '""' },
        { key: '机审时间', value: '' }
      ],
      // 时间线
      timeLineList: [],
      // 用户搜索
      searchList: [{ key: '大鹏号', value: 'DAPENGACCOUNT' }],
      // 展示方式
      displayRuleList: [{ dictLabel: '全部', dictValue: '' }],
      userAttList: [{ dictLabel: '全部', dictValue: '' }], // 用户属性
      linkActiveList: [{ id: '', name: '全部' }],
      collegeList: [
        // 学院
        { dictLabel: '全部学院', dictValue: '' }
      ]
    }
  },
  watch: {
    'formInline.createTime': {
      handler(newVal, oldVal) {
        if (newVal && newVal.length > 1) {
          this.formInline.startTime = newVal[0]
          this.formInline.endTime = newVal[1]
        } else {
          this.formInline.startTime = ''
          this.formInline.endTime = ''
        }
      },
      deep: true
    }
  },
  mounted() {
    this.getStatusList()
    this.getLinkActive()
    this.getCheckUser()
  },
  methods: {
    /* 搜索 */
    toSearch(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('toSearch')
        } else {
          return false
        }
      })
    },
    /* 重置 */
    reset() {
      this.$refs['ruleForm'].resetFields()
      //设置默认数据
      this.setDefaultValue()
    },
    /* 获取数据状态 */
    async getStatusList() {
      // 人审结果
      let data = await sysNormalDisable('sys_check_statu_s', 'personStatus')
      this.checkStatuList = this.checkStatuList.concat(data)
      // 机审结果
      let machine = await sysNormalDisable('sys_machine_statu')
      this.machineStatuList = this.machineStatuList.concat(machine)
      // 排序规则
      this.orderList = await sysNormalDisable('work_audit_sort')
      // 作品类型
      let workType = await sysNormalDisable('sys_work_type', 'workType')
      this.workTypeList = this.workTypeList.concat(workType)
      // 时间线
      let timeLine = await sysNormalDisable('sys_jobwork_time')
      this.timeLineList = [...timeLine, { dictLabel: '全部', dictValue: '' }]
      // 展示方式
      let rule = await sysNormalDisable('video_work_display_rule', 'ruleType')
      this.displayRuleList = this.displayRuleList.concat(rule)
      // 用户属性
      let UserAttr = await sysNormalDisable(
        'comment_user_attributes',
        'checkUserAttr'
      )
      this.userAttList = this.userAttList.concat(UserAttr)
      // 学院
      let collegeList = await sysNormalDisable('sys_college', 'collegeType')
      this.collegeList = this.collegeList.concat(collegeList)
      this.setDefaultValue()
      //触发列表获取权限
      this.$emit('toSearch')
    },
    /*设置默认数据*/
    setDefaultValue() {
      this.formInline.sortRule = this.orderList[0].dictValue
      this.formInline.timeLine = this.timeLineList[0].dictValue
      this.formInline.userType = this.searchList[0].value
      this.formInline.timeRule = this.timeTypeList[0].value
    },
    // 审核人
    getCheckUser() {
      getDpNum({ type: 'OPERATORS' }, (response) => {
        this.personList = this.personList.concat(response)
      })
    },
    // 获取关联活动列表
    async getLinkActive() {
      let linkContentType = 'WORKS'
      let linkActiveList = await getWorkListActivities(linkContentType)
      this.linkActiveList = this.linkActiveList.concat(linkActiveList)
    }
  }
}
</script>

<style lang="less">
#workCheckTopSearch {
  .el-input {
    &.el-input--suffix {
      width: 185px !important;
    }
  }

  label.el-form-item__label {
    width: 70px !important;
  }
}
</style>
